<?php
namespace Home\Controller;

class RegisterController extends HomeBaseController
{

    public function index()
    {
        //判断是否是推荐注册
        $this->display('register/index');
    }

    public function regverifyCode(){
        $con=array('useNoise' => false,'length'=>4,'useCurve'=>false);
        $Verify = new \Think\Verify($con);
        $Verify->expire=120;//2分钟
        $Verify->fontSize=16;
        $Verify->entry();
    }
    
    /**
     * 注册
     */
    public function register(){
        $mobile=I('mobile','');
        $email=I('email','');
        $account=I('account','');
        $passwd=I('passwd','');
        $repasswd=I('repasswd','');
        $qq=I('qq','');
         $code=I('code','');//输入的验证码
        $verify = new \Think\Verify();
        
        if(!$verify->check($code)){
            $this->ajaxReturn(array('status'=>'2','msg' => $code.'验证码错误或已过期！'));//0错误，1成功
            exit;
        }
        if($passwd!=$repasswd){
            $this->ajaxReturn(array('status'=>'2','msg' => '两次密码不同！'));//0错误，1成功
            exit;
        }
       $UserAcc = D("UserAcc");
       $data['createdate']=date("Y-m-d H:i:s ");
       $data['mobile']=$mobile;
       $data['email']=$email;
       $data['account']=$account;
       $data['paswd']=$passwd;
       $data['qq']=$qq;
       if (!$UserAcc->create($data)){
            $this->ajaxReturn(array('status'=>'2','msg' => $UserAcc->getError()));//0错误，1成功
            exit;
        }else{
            $UserAcc->add($data);
            $this->ajaxReturn(array('status'=>'1','redirect' => U("Login/index"),'msg'=>"注册成功！"));//0错误，1成功
            exit;
        }
    }
    
}